// Thud - a dynamic object-oriented language
// Copyright (C) 2009,2010 David H. Hovemeyer <david.hovemeyer@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

/*
 * TextCoder.h
 *
 *  Created on: Dec 14, 2009
 *      Author: dhovemey
 */

#ifndef TEXTCODER_H_
#define TEXTCODER_H_

#include <cwchar>

class InputStream;
class OutputStream;

/**
 * A TextCoder encodes and decodes Unicode code points to/from OutputStreams and InputStreams.
 */
class TextCoder {
private:
	TextCoder(const TextCoder &);
	TextCoder& operator=(const TextCoder &);

public:
	TextCoder();
	virtual ~TextCoder();

	/**
	 * Decodes a single code point from given input stream and returns it.
	 *
	 * @param in the InputStream to read from
	 * @return the decoded code point, or -1 if end of file or a decoding error occurs
	 */
	virtual long decode(InputStream *in) = 0;

	/**
	 * Encodes a single code point and writes it to given output stream.
	 * @param c   the code point to write
	 * @param out the OutputStream to write to
	 * @return true if the character is successfully encoded and written, false if
	 *              an I/O error or encoding error occurs
	 */
	virtual bool encode(wchar_t c, OutputStream *out) = 0;

	/**
	 * @return true if an error occurred when decode() was called, false if no error occurred
	 */
	virtual bool decodeError() = 0;

	/**
	 * @return true if an error occurred when encode() was called, false if no error occurred
	 */
	virtual bool encodeError() = 0;
};

#endif /* TEXTCODER_H_ */

